﻿using AutoMapper;
using MediatR;
using S.EliminationOrDath.API.Application.Command.SheepDeathCommand;
using S.EliminationOrDath.Domain.Models;
using S.EliminationOrDath.Infrastructure.Interface;

namespace S.EliminationOrDath.API.Application.CommandHandlers.SheepDeathCommandHandler
{
    public class SheepDeathBatchAddCommandHandler : IRequestHandler<SheepDeathBatchAddCommand, bool>
    {
        private readonly ISheepDeathRepository _sheepDeathRepository;
        private readonly IMapper _mapper;
        public SheepDeathBatchAddCommandHandler(ISheepDeathRepository heepDeathRepository,IMapper mapper)
        {
            _sheepDeathRepository= heepDeathRepository;
            _mapper= mapper;
        }
        /// <summary>
        /// 批量添加羊只死亡信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<bool> Handle(SheepDeathBatchAddCommand request, CancellationToken cancellationToken)
        {
            List<DeathModel?>? model = new List<DeathModel?>();
            model = _mapper.Map<List<DeathModel?>?>(request.BatchDeath);
            return await _sheepDeathRepository.AddRange(model);
        }
    }
}
